package com.weibo.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import com.weibo.db.DataBaseConnection;
import com.weibo.entity.JianceFenlei;
import com.weibo.entity.JianceMail;

public class JianceMailService  extends  DataBaseConnection{
	
	public void delete(int id){
		try {
			String sql = "delete from t_jiance_mail where id="+id ;
				super.delete(sql);
			
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				super.closeAll();
			}
	}
	
	public void add(JianceMail mail){
		
		try {
			String sql = "insert into t_jiance_mail(mail,name) " +
					"values ('"+mail.getMail()+"','"+mail.getName()+"')";
				super.save(sql);
			
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				super.closeAll();
			}
	}
	
	
	public List<Object> findAll(){
		
		String sql = "select * from t_jiance_mail";
		ResultSet rs=null;
		try {
			rs = super.getResultSet(sql, null);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		List<Object> list = new LinkedList<Object>();
		JianceMail mail = null;
		
		try {
			while(rs.next()){
				mail = new JianceMail();
				mail.setId(rs.getInt("id"));
				mail.setMail(rs.getString("mail"));
				mail.setName(rs.getString("name"));
				list.add(mail);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally{
			super.closeAll();
		}
		return list;
	}
	
public List<JianceMail> list(){
		
		String sql = "select * from t_jiance_mail";
		ResultSet rs=null;
		try {
			rs = super.getResultSet(sql, null);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		List<JianceMail> list = new LinkedList<JianceMail>();
		JianceMail mail = null;
		
		try {
			while(rs.next()){
				mail = new JianceMail();
				mail.setId(rs.getInt("id"));
				mail.setMail(rs.getString("mail"));
				mail.setName(rs.getString("name"));
				list.add(mail);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally{
			super.closeAll();
		}
		return list;
	}
	
}
